package uz.rt.dicom.data;

import uz.rt.dicom.tag.DicomTag;

import java.util.ArrayList;
import java.util.Iterator;

public class DataSet implements Iterable<IDataElement>
{
// ------------------------------ FIELDS ------------------------------

    private ArrayList<IDataElement> value = new ArrayList<IDataElement>();

// --------------------------- CONSTRUCTORS ---------------------------

    public DataSet()
    {

    }

// ------------------------ INTERFACE METHODS ------------------------


// --------------------- Interface Iterable ---------------------

    public Iterator<IDataElement> iterator()
    {
        return value.iterator();
    }

// -------------------------- OTHER METHODS --------------------------

    public void add(IDataElement element)
    {
        value.add(element);
    }

    public IDataElement get(int index)
    {
        return value.get(index);
    }

    /**
     * Get an IDataElement based on a given DicomTag.
     *
     * @param tag DicomTag
     * @return IDataElement is returned when the DicomTag is found, otherwise a null value is returned.
     */
    public IDataElement getByTag(DicomTag tag)
    {
        for (IDataElement element : value)
        {
            DicomTag dicomTag = element.getTag();
            if (dicomTag.equals(tag))
                return element;
        }
        return null;
    }

    public void remove(int index)
    {
        value.remove(index);
    }

    public void remove(IDataElement element)
    {
        value.remove(element);
    }

    public void set(int index, IDataElement element)
    {
        value.set(index, element);
    }
}
